package net.lab1024.sa.admin.config;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

/**
 * PDF解析配置
 *
 * @Author 1024创新实验室
 */
@Component
@ConfigurationProperties(prefix = "pdf")
public class PdfConfig {

    /**
     * Tesseract OCR数据路径
     */
    private String tessdataPath = "D:/tesseract/tessdata";

    /**
     * 文件上传大小限制（MB）
     */
    private Integer uploadMaxFileSize = 50;

    /**
     * 请求大小限制（MB）
     */
    private Integer uploadMaxRequestSize = 50;

    /**
     * OCR性能优化配置
     */
    private Ocr ocr = new Ocr();

    public String getTessdataPath() {
        return tessdataPath;
    }

    public void setTessdataPath(String tessdataPath) {
        this.tessdataPath = tessdataPath;
    }

    public Integer getUploadMaxFileSize() {
        return uploadMaxFileSize;
    }

    public void setUploadMaxFileSize(Integer uploadMaxFileSize) {
        this.uploadMaxFileSize = uploadMaxFileSize;
    }

    public Integer getUploadMaxRequestSize() {
        return uploadMaxRequestSize;
    }

    public void setUploadMaxRequestSize(Integer uploadMaxRequestSize) {
        this.uploadMaxRequestSize = uploadMaxRequestSize;
    }

    public Ocr getOcr() {
        return ocr;
    }

    public void setOcr(Ocr ocr) {
        this.ocr = ocr;
    }

    /**
     * OCR配置内部类
     */
    public static class Ocr {
        /**
         * 线程池大小
         */
        private Integer threadPoolSize = 4;

        /**
         * 图片DPI
         */
        private Integer imageDpi = 200; // 降低默认DPI以提高速度

        /**
         * 是否启用图片预处理
         */
        private Boolean enableImagePreprocessing = true;

        /**
         * 是否启用多语言识别
         */
        private Boolean enableMultiLanguage = true;

        /**
         * 最小识别文本长度
         */
        private Integer minTextLength = 5;

        /**
         * 图像对比度增强系数
         */
        private Double contrastEnhancement = 1.2;

        /**
         * 是否启用LSTM引擎
         */
        private Boolean enableLstmEngine = true;

        /**
         * 页面分割模式
         */
        private Integer pageSegMode = 1;

        /**
         * 默认语言包
         */
        private String defaultLanguage = "chi_sim";

        /**
         * 语言包列表（按优先级排序）
         */
        private String[] languages = {"chi_sim", "eng"};

        /**
         * 多语言组合列表
         */
        private String[] languageCombinations = {"chi_sim+eng", "eng+chi_sim", "chi_sim", "eng"};

        /**
         * 混合优化配置
         */
        private Optimization optimization = new Optimization();

        public Integer getThreadPoolSize() {
            return threadPoolSize;
        }

        public void setThreadPoolSize(Integer threadPoolSize) {
            this.threadPoolSize = threadPoolSize;
        }

        public Integer getImageDpi() {
            return imageDpi;
        }

        public void setImageDpi(Integer imageDpi) {
            this.imageDpi = imageDpi;
        }

        public Boolean getEnableImagePreprocessing() {
            return enableImagePreprocessing;
        }

        public void setEnableImagePreprocessing(Boolean enableImagePreprocessing) {
            this.enableImagePreprocessing = enableImagePreprocessing;
        }

        public Boolean getEnableMultiLanguage() {
            return enableMultiLanguage;
        }

        public void setEnableMultiLanguage(Boolean enableMultiLanguage) {
            this.enableMultiLanguage = enableMultiLanguage;
        }

        public Integer getMinTextLength() {
            return minTextLength;
        }

        public void setMinTextLength(Integer minTextLength) {
            this.minTextLength = minTextLength;
        }

        public Double getContrastEnhancement() {
            return contrastEnhancement;
        }

        public void setContrastEnhancement(Double contrastEnhancement) {
            this.contrastEnhancement = contrastEnhancement;
        }

        public Boolean getEnableLstmEngine() {
            return enableLstmEngine;
        }

        public void setEnableLstmEngine(Boolean enableLstmEngine) {
            this.enableLstmEngine = enableLstmEngine;
        }

        public Integer getPageSegMode() {
            return pageSegMode;
        }

        public void setPageSegMode(Integer pageSegMode) {
            this.pageSegMode = pageSegMode;
        }

        public String getDefaultLanguage() {
            return defaultLanguage;
        }

        public void setDefaultLanguage(String defaultLanguage) {
            this.defaultLanguage = defaultLanguage;
        }

        public String[] getLanguages() {
            return languages;
        }

        public void setLanguages(String[] languages) {
            this.languages = languages;
        }

        public String[] getLanguageCombinations() {
            return languageCombinations;
        }

        public void setLanguageCombinations(String[] languageCombinations) {
            this.languageCombinations = languageCombinations;
        }

        public Optimization getOptimization() {
            return optimization;
        }

        public void setOptimization(Optimization optimization) {
            this.optimization = optimization;
        }

        /**
         * 混合优化配置内部类
         */
        public static class Optimization {
            /**
             * 是否启用智能页面预分析
             */
            private Boolean enableSmartPageAnalysis = true;

            /**
             * 是否启用异步并行处理
             */
            private Boolean enableAsyncProcessing = true;

            /**
             * 是否启用结果缓存
             */
            private Boolean enableResultCache = true;

            /**
             * 是否启用批量数据库操作
             */
            private Boolean enableBatchSave = true;

            /**
             * 最大图像尺寸（像素）
             */
            private Integer maxImageDimension = 2000;

            /**
             * 缓存最大条目数
             */
            private Integer maxCacheSize = 1000;

            /**
             * 批量保存大小
             */
            private Integer batchSize = 10;

            /**
             * 页面分析超时时间（秒）
             */
            private Integer pageAnalysisTimeout = 30;

            /**
             * 页面处理超时时间（秒）
             */
            private Integer pageProcessingTimeout = 300;

            public Boolean getEnableSmartPageAnalysis() {
                return enableSmartPageAnalysis;
            }

            public void setEnableSmartPageAnalysis(Boolean enableSmartPageAnalysis) {
                this.enableSmartPageAnalysis = enableSmartPageAnalysis;
            }

            public Boolean getEnableAsyncProcessing() {
                return enableAsyncProcessing;
            }

            public void setEnableAsyncProcessing(Boolean enableAsyncProcessing) {
                this.enableAsyncProcessing = enableAsyncProcessing;
            }

            public Boolean getEnableResultCache() {
                return enableResultCache;
            }

            public void setEnableResultCache(Boolean enableResultCache) {
                this.enableResultCache = enableResultCache;
            }

            public Boolean getEnableBatchSave() {
                return enableBatchSave;
            }

            public void setEnableBatchSave(Boolean enableBatchSave) {
                this.enableBatchSave = enableBatchSave;
            }

            public Integer getMaxImageDimension() {
                return maxImageDimension;
            }

            public void setMaxImageDimension(Integer maxImageDimension) {
                this.maxImageDimension = maxImageDimension;
            }

            public Integer getMaxCacheSize() {
                return maxCacheSize;
            }

            public void setMaxCacheSize(Integer maxCacheSize) {
                this.maxCacheSize = maxCacheSize;
            }

            public Integer getBatchSize() {
                return batchSize;
            }

            public void setBatchSize(Integer batchSize) {
                this.batchSize = batchSize;
            }

            public Integer getPageAnalysisTimeout() {
                return pageAnalysisTimeout;
            }

            public void setPageAnalysisTimeout(Integer pageAnalysisTimeout) {
                this.pageAnalysisTimeout = pageAnalysisTimeout;
            }

            public Integer getPageProcessingTimeout() {
                return pageProcessingTimeout;
            }

            public void setPageProcessingTimeout(Integer pageProcessingTimeout) {
                this.pageProcessingTimeout = pageProcessingTimeout;
            }
        }
    }
} 